/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.sync.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.pitop.sync.api.SyncDataTraceFeignApi;
import com.pitop.core.exceptions.SyncDataTraceException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.sync.entity.SyncDataTrace;


/**
 * 同步数据
 *
 * @author pi-top
 */
@Service("syncDataTraceSVImpl")
@Slf4j
public class SyncDataTraceSVImpl {

    @Autowired
    private SyncDataTraceFeignApi syncDataTraceFeignApi;

    /**
     * 加载一个对象SyncDataTrace
     *
     * @param id id* @param syncTraceCode 同步追踪编码
     * @return SyncDataTrace
     */
    public SyncDataTrace load(java.lang.Long id, java.lang.String syncTraceCode) {
        if (id == null && syncTraceCode == null) {
            throw new SyncDataTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncDataTraceFeignApi.load(id, syncTraceCode);
    }

    /**
     * 加载一个对象SyncDataTrace 通过id
     *
     * @param id id
     * @return SyncDataTrace
     */
    public SyncDataTrace loadById(java.lang.Long id) {
        if (id == null) {
            throw new SyncDataTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncDataTraceFeignApi.loadById(id);
    }

    /**
     * 加载一个对象SyncDataTrace 通过syncTraceCode
     *
     * @param syncTraceCode 同步追踪编码
     * @return SyncDataTrace
     */
    public SyncDataTrace loadBySyncTraceCode(java.lang.String syncTraceCode) {
        if (syncTraceCode == null) {
            throw new SyncDataTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return syncDataTraceFeignApi.loadBySyncTraceCode(syncTraceCode);
    }


    /**
     * 删除对象SyncDataTrace
     *
     * @param id id* @param syncTraceCode 同步追踪编码
     * @return SyncDataTrace
     */

    public void delete(java.lang.Long id, java.lang.String syncTraceCode) {
        if (id == null && syncTraceCode == null) {
            throw new SyncDataTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        syncDataTraceFeignApi.delete(id, syncTraceCode);
    }


    /**
     * 查询SyncDataTrace分页
     *
     * @param syncDataTrace 对象
     * @param curPage       当前页
     * @param pageSize      分页条数
     * @return List<SyncDataTrace>
     */
    public List<SyncDataTrace> list(SyncDataTrace syncDataTrace, int curPage, int pageSize) {
        return syncDataTraceFeignApi.list(syncDataTrace, curPage, pageSize);
    }

    /**
     * 查询SyncDataTrace分页
     *
     * @param id       id* @param syncTraceCode  同步追踪编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<SyncDataTrace>
     */
    public List<SyncDataTrace> list(java.lang.Long id, java.lang.String syncTraceCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        SyncDataTrace syncDataTrace = new SyncDataTrace();
        syncDataTrace.setId(id);
        syncDataTrace.setSyncTraceCode(syncTraceCode);

        return syncDataTraceFeignApi.list(syncDataTrace, curPage, pageSize);
    }


    public int count(java.lang.Long id, java.lang.String syncTraceCode) {
        return syncDataTraceFeignApi.count(id, syncTraceCode);
    }


    public int count(SyncDataTrace syncDataTrace) {
        return syncDataTraceFeignApi.count(syncDataTrace);
    }


    /**
     * 保存
     *
     * @param syncDataTrace 实体
     * @throws BaseException
     */
    public void save(SyncDataTrace syncDataTrace) {
        if (syncDataTrace == null) {
            throw new SyncDataTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        syncDataTraceFeignApi.build(syncDataTrace);
    }

    /**
     * 更新
     *
     * @param syncDataTrace 实体
     * @throws BaseException
     */
    public void modify(SyncDataTrace syncDataTrace) {
        if (syncDataTrace == null) {
            throw new SyncDataTraceException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        syncDataTraceFeignApi.modify(syncDataTrace);
    }

}
